Make GtkIconInfo a GObject
authorAlexander Larsson <alexl@redhat.com>
Wed, 13 Feb 2013 14:05:02 +0000 (15:05 +0100)
committerAlexander Larsson <alexl@redhat.com>
Thu, 14 Feb 2013 21:07:25 +0000 (22:07 +0100)
This is necessary in order to have async operations on it.
All the old copy/free functions keeps working, and g_boxed_copy on a GObject
also works, so this should be mostly compatible, but techncally its a minor
ABI break since the GType changes fundamental type. Changes like this has
happened before though, like with GVariant becomming its own fundamental
type.

https://bugzilla.gnome.org/show_bug.cgi?id=693802

gtk/gtkicontheme.c
gtk/gtkicontheme.h

index 0520686206cdd467cbc034b9af24d4fcaf32c7b9..3b79a55f3e0c0b50c1c71500acdb86b52a80f5df 100644 (file)
@@ -225,8 +225,15 @@ struct _SymbolicPixbufCache {
   SymbolicPixbufCache *next;
 };
 
+struct _GtkIconInfoClass
+{
+  GObjectClass parent_class;
+};
+
 struct _GtkIconInfo
 {
+  GObject parent_instance;
+
   /* Information about the source
    */
   IconInfoKey key;
@@ -256,8 +263,6 @@ struct _GtkIconInfo
   guint forced_size     : 1;
   guint emblems_applied : 1;
 
-  guint ref_count;
-
   /* Cached information if we go ahead and try to load
    * the icon.
    */
@@ -2971,19 +2976,20 @@ icon_data_free (GtkIconData *icon_data)
  * GtkIconInfo
  */
 
-G_DEFINE_BOXED_TYPE (GtkIconInfo, gtk_icon_info,
-                     gtk_icon_info_copy,
-                     gtk_icon_info_free)
+static void gtk_icon_info_class_init (GtkIconInfoClass *klass);
 
-static GtkIconInfo *
-icon_info_new (void)
-{
-  GtkIconInfo *icon_info = g_slice_new0 (GtkIconInfo);
+G_DEFINE_TYPE (GtkIconInfo, gtk_icon_info, G_TYPE_OBJECT)
 
+static void
+gtk_icon_info_init (GtkIconInfo *icon_info)
+{
   icon_info->scale = -1.;
-  icon_info->ref_count = 1;
+}
 
-  return icon_info;
+static GtkIconInfo *
+icon_info_new (void)
+{
+  return g_object_new (GTK_TYPE_ICON_INFO, NULL);
 }
 
 static GtkIconInfo *
@@ -3015,9 +3021,7 @@ gtk_icon_info_copy (GtkIconInfo *icon_info)
   
   g_return_val_if_fail (icon_info != NULL, NULL);
 
-  icon_info->ref_count++;
-
-  return icon_info;
+  return g_object_ref (icon_info);
 }
 
 /**
@@ -3033,9 +3037,13 @@ gtk_icon_info_free (GtkIconInfo *icon_info)
 {
   g_return_if_fail (icon_info != NULL);
 
-  icon_info->ref_count--;
-  if (icon_info->ref_count > 0)
-    return;
+  g_object_unref (icon_info);
+}
+
+static void
+gtk_icon_info_finalize (GObject *object)
+{
+  GtkIconInfo *icon_info = (GtkIconInfo *) object;
 
   if (icon_info->in_cache)
     g_hash_table_remove (icon_info->in_cache->priv->info_cache, &icon_info->key);
@@ -3057,7 +3065,15 @@ gtk_icon_info_free (GtkIconInfo *icon_info)
 
   symbolic_pixbuf_cache_free (icon_info->symbolic_pixbuf_cache);
 
-  g_slice_free (GtkIconInfo, icon_info);
+  G_OBJECT_CLASS (gtk_icon_info_parent_class)->finalize (object);
+}
+
+static void
+gtk_icon_info_class_init (GtkIconInfoClass *klass)
+{
+  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+  gobject_class->finalize = gtk_icon_info_finalize;
 }
 
 /**
index 8852110cdb90d9f5df5dcf9356673cae97bdcfd8..cf284291cb015d8ee53e9e600a2f0ef3d4c5fcd8 100644 (file)
 G_BEGIN_DECLS
 
 #define GTK_TYPE_ICON_INFO              (gtk_icon_info_get_type ())
+#define GTK_ICON_INFO(obj)              (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_INFO, GtkIconInfo))
+#define GTK_ICON_INFO_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_ICON_INFO, GtkIconInfoClass))
+#define GTK_IS_ICON_INFO(obj)           (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_ICON_INFO))
+#define GTK_IS_ICON_INFO_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_ICON_INFO))
+#define GTK_ICON_INFO_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_ICON_INFO, GtkIconInfoClass))
 
 #define GTK_TYPE_ICON_THEME             (gtk_icon_theme_get_type ())
 #define GTK_ICON_THEME(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_ICON_THEME, GtkIconTheme))
@@ -44,6 +49,7 @@ G_BEGIN_DECLS
  * an icon theme.
  */
 typedef struct _GtkIconInfo         GtkIconInfo;
+typedef struct _GtkIconInfoClass    GtkIconInfoClass;
 typedef struct _GtkIconTheme        GtkIconTheme;
 typedef struct _GtkIconThemeClass   GtkIconThemeClass;
 typedef struct _GtkIconThemePrivate GtkIconThemePrivate;